<!DOCTYPE html>
<html>
  <head>
    <title>OpenIMU - GPS Map</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <style>
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
var map;
var marker;
var myLatLng;
var track;
function initMap() {
	myLatLng = new google.maps.LatLng(45.4010, -71.8824);
	map = new google.maps.Map(document.getElementById('map'), {
		center: {lat: 45.4010, lng: -71.8824},
		zoom: 15,
		streetViewControl: false,
		mapTypeId: google.maps.MapTypeId.HYBRID
		
	});
	
	map.setOptions({draggable: true, zoomControl: true, scrollwheel: true, disableDoubleClickZoom: false});
	
	marker = new google.maps.Marker({
		position: myLatLng,
		map: map,
		title: 'Votre position',
		icon: 'http://maps.google.com/mapfiles/kml/pal3/icon32.png'
	});
	track = new google.maps.Polyline({
		strokeColor: '#6699ff',
		strokeOpacity: 0.8,
		strokeWeight: 2
	});
	selected_track = new google.maps.Polyline({
		strokeColor: '#00ff00',
		strokeOpacity: 0.8,
		strokeWeight: 2
	});
	track.setMap(map);
	selected_track.setMap(map);
}

function addPosition(lat, lng){
  var path = track.getPath();
  
  myLatLng = new google.maps.LatLng(lat, lng);
  // Because path is an MVCArray, we can simply append a new coordinate
  // and it will automatically appear.
  path.push(myLatLng);
}

function addSelectedPosition(lat, lng){
  var path = selected_track.getPath();
  
  myLatLng = new google.maps.LatLng(lat, lng);
  // Because path is an MVCArray, we can simply append a new coordinate
  // and it will automatically appear.
  path.push(myLatLng);
}

function clearSelectedPath(){
	selected_track.getPath().clear();
}

function setCurrentPosition(lat, lng) {
  var path = track.getPath();
  
  myLatLng = new google.maps.LatLng(lat, lng);
  // Because path is an MVCArray, we can simply append a new coordinate
  // and it will automatically appear.
  path.push(myLatLng);
  // Move marker
  marker.setPosition(myLatLng);
  
  // Recenter map
  map.setCenter(myLatLng);
  //map.setZoom(15);
}

function setMarkerPosition(lat, lng){
  myLatLng = new google.maps.LatLng(lat, lng);
  marker.setPosition(myLatLng);
  map.setCenter(myLatLng);
}
function clearMap() {
	path.clear();
	marker.clear();
}
function zoomIn(){
	map.setZoom(map.zoom+1);
}
function zoomOut(){
	map.setZoom(map.zoom-1);
}
function resetZoom(){
	map.setZoom(15);
}
function isZoomed(){
	return map.zoom == 15;
}
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDzwyGnWwge77qFtkOYHBQ0D76JIrLRic8&callback=initMap"
        async defer></script>
  </body>
</html>

